package service

import (
	"context"
	"mini-app/internal/app/grpc/client"
	"mini-app/internal/app/grpc/protoc/sale_adminc"

	"192.168.1.75/go-pkg/errorx"
)

type Coupon struct{}

func (Coupon) CheckCode(ctx context.Context, SalesID string, Code string) error {
	saleAdminClient, err := client.GetSaleAdminClient()
	if err != nil {
		return errorx.New("grpc client error", -1)
	}
	rsp, err := saleAdminClient.CheckCode(ctx, &sale_adminc.CheckCodeReq{
		SalesId: SalesID,
		Code:    Code,
		Online:  1,
	})
	if err != nil {
		return errorx.New("优惠码验证错误", -1)
	}
	if rsp.Code != 0 {
		return errorx.New(rsp.Msg, int(rsp.Code))
	}
	return nil
}
